A=$(shell pwd)

include config.mk
Src=$A/../svns/awk/branches/timm#
LibAwk=$(Src)/../tiny/lib.awk


Binned=$(Data)_d$(Bins)


Dirs= $(Tmp) $(Safe)

Debug=@pgawk --dump-variables=$(Tmp)/vars.out \
            --profile=$(Tmp)/profile.out \
            -f $(LibAwk) #
Run=@gawk -f $(LibAwk) #

ready  : $(LibAwk)    
	@mkdir -p $(Dirs)
test1  : ready $(Data) 
	$(Debug) --source 'BEGIN {print 1+1}' 
ranges : ready $(Data) 
	$(Debug) -f ranges.awk \
                 --source 'END {histograms()}' Bins=$(Bins) $(Data) \
                 > $(Safe)/ranges$(Bins).txt
discretize: $(Binned)

$(Binned) : ready $(Data)
	$(Debug) -f ranges.awk  --source 'END {asBins()}' Bins=$(Bins) $(Data) > $@
	@echo $@

contrast :
	$(Debug) -f bore.awk Target=$(Target) Support=$(Support) \
                  Seed=$(Seed) Select=$(Select) $(Binned) >  $(Safe)/contrast.txt  

nomogram : 	
	$(Debug) -f nomogram.awk  Control=$(Control) $(Safe)/contrast.txt | sort -n -k 1 -r -k 2 -r -k 3

all : ranges discretize contrast nomogram

stability :
	@rm -rf ~/var/nomos1.txt
	@rm -rf ~/var/nomos$(Bins).txt
	@$(foreach x,1 2 3, \
	     $(MAKE) Select=0.67 Seed=$(shell echo $$RANDOM) Target=quitter contrast nomogram \
                         |  tee -a $(Safe)/nomos1.txt ;)
	@$(foreach x,1 2 3, \
	     $(MAKE) Select=0.67 Seed=$(shell echo $$RANDOM) Target=stayer  contrast nomogram \
                         |  tee -a $(Safe)/nomos$(Bins).txt ;)

candyPrep :
	@gawk -F, -f candyPrep.awk data/candyland.csv | sed 's/First3//g' >  data/candylandReady.csv